package domain;

import java.util.Date;

import javax.persistence.Access;
import javax.persistence.AccessType;
import javax.persistence.Entity;
import javax.persistence.Index;
import javax.persistence.ManyToOne;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import javax.validation.Valid;
import javax.validation.constraints.Digits;
import javax.validation.constraints.Min;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Past;

import org.hibernate.validator.constraints.NotBlank;
import org.springframework.format.annotation.DateTimeFormat;

@Entity
@Access(AccessType.PROPERTY)
@Table(indexes = {@Index(columnList = "updateMoment")})
public class WorkUpdate extends DomainEntity {
	//Constructors

	public WorkUpdate() {
		super();
	}
	
	//Attributes
	private String description;
	private Date updateMoment;
	private double amountOfWork;

	@NotBlank
	public String getDescription() {
		return description;
	}

	public void setDescription(String description) {
		this.description = description;
	}

	@NotNull
	@Past
	@Temporal(TemporalType.TIMESTAMP)
	@DateTimeFormat(pattern = "dd/MM/yyyy HH:mm")
	public Date getUpdateMoment() {
		return updateMoment;
	}

	public void setUpdateMoment(Date updateMoment) {
		this.updateMoment = updateMoment;
	}

	@Digits(integer = 9, fraction = 2)
	@Min(0)
	public double getAmountOfWork() {
		return amountOfWork;
	}

	public void setAmountOfWork(double amountOfWork) {
		this.amountOfWork = amountOfWork;
	}

	// Relationships
	private Registration registration;

	@Valid
	@NotNull
	@ManyToOne(optional = false)
	public Registration getRegistration() {
		return registration;
	}

	public void setRegistration(Registration registration) {
		this.registration = registration;
	}
}
